﻿@model FieldControlViewModel
@{
	string dataValue = Model.FieldValue;
	string dateType = Model.Settings[0];//year,month,date,time,datetime
	string format = string.Empty;
	switch (dateType)
	{
		case "year":
			format = "yyyy";
			if(string.IsNullOrEmpty(dataValue) && Model.Settings[1] == "1")
			{
				dataValue = DateTime.Now.ToString(format);
			}
			break;
		case "month":
			format = "yyyy-MM";
			if (string.IsNullOrEmpty(dataValue) && Model.Settings[1] == "1")
			{
				dataValue = DateTime.Now.ToString(format);
			}
			break;
		case "date":
			format = "yyyy-MM-dd";
			if (string.IsNullOrEmpty(dataValue) && Model.Settings[1] == "1")
			{
				dataValue = DateTime.Now.ToString(format);
			}
			break;
		case "time":
			format = "HH:mm:ss";
			if (string.IsNullOrEmpty(dataValue) && Model.Settings[1] == "1")
			{
				dataValue = DateTime.Now.ToString(format);
			}
			break;
		case "datetime":
			format = "yyyy-MM-dd HH:mm:ss";
			if (string.IsNullOrEmpty(dataValue) && Model.Settings[1] == "1")
			{
				dataValue = DateTime.Now.ToString(format);
			}
			break;
	}
	string dataVal = string.Empty;
	string dataValMsg = string.Empty;
	if (Model.EnableNull)
	{
		dataVal += " data-val-required=\"不能为空\" ";
	}
	if (!string.IsNullOrEmpty(dataVal))
	{
		dataVal += " data-val=\"true\" ";
		dataValMsg = " data-valmsg-for=\"" + Model.Prefix + Model.FieldName + "\" data-valmsg-replace=\"true\"";
	}
}
<div class="layui-input-inline">
	<input type="text" class="layui-input" name="@Model.Prefix@Model.FieldName" id="@Model.Prefix@Model.FieldName" value="@dataValue" @Html.Raw(dataVal) />
</div>
<div class="layui-input-inline layui-input-company">
	<span class="layui-bg-green">@Model.Description</span>
	<span style="color:red;" @Html.Raw(dataValMsg)></span>
</div>
<script type="text/javascript">
	jQuery(function () {
		layui.use('laydate', function () {
			var laydate = layui.laydate;
			laydate.render({
				elem: '#@Model.Prefix@Model.FieldName'
				, type: '@dateType'
				, range: @Model.Settings[2].ToBoolean().ToString().ToLower()
				, format: '@format'
			});
		});
	});
</script>